/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Profile.java
 *
 * Created on Jun 27, 2011, 8:04:50 PM
 */
package chat;

import javax.swing.JOptionPane;

/**
 *
 * @author mingq
 */
public class Profile extends javax.swing.JDialog {

    private String mMyUid;
    private ChatMain mParent;

    /** Creates new form Profile */
    public Profile(java.awt.Frame parent, boolean modal, String uid, String nick, ChatMain pa) {
        super(parent, modal);
        initComponents();
        mMyUid = uid;
        mParent = pa;
        lblOldNick.setText(nick);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btnChangeNick = new javax.swing.JButton();
        txtNewNick = new javax.swing.JTextField();
        txtNewPassword = new javax.swing.JTextField();
        btnChangePassword = new javax.swing.JButton();
        txtNewPasswordConfirm = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblOldNick = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(chat.ChatApp.class).getContext().getResourceMap(Profile.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        btnChangeNick.setText(resourceMap.getString("btnChangeNick.text")); // NOI18N
        btnChangeNick.setName("btnChangeNick"); // NOI18N
        btnChangeNick.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnChangeNickMouseClicked(evt);
            }
        });

        txtNewNick.setText(resourceMap.getString("txtNewNick.text")); // NOI18N
        txtNewNick.setName("txtNewNick"); // NOI18N

        txtNewPassword.setText(resourceMap.getString("txtNewPassword.text")); // NOI18N
        txtNewPassword.setName("txtNewPassword"); // NOI18N

        btnChangePassword.setText(resourceMap.getString("btnChangePassword.text")); // NOI18N
        btnChangePassword.setName("btnChangePassword"); // NOI18N
        btnChangePassword.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnChangePasswordMouseClicked(evt);
            }
        });

        txtNewPasswordConfirm.setText(resourceMap.getString("txtNewPasswordConfirm.text")); // NOI18N
        txtNewPasswordConfirm.setName("txtNewPasswordConfirm"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        lblOldNick.setText(resourceMap.getString("lblOldNick.text")); // NOI18N
        lblOldNick.setName("lblOldNick"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(btnChangeNick)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 153, Short.MAX_VALUE)
                        .addComponent(btnChangePassword))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblOldNick))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtNewNick, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNewPasswordConfirm, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                            .addComponent(txtNewPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblOldNick)
                    .addComponent(jLabel3)
                    .addComponent(txtNewPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNewNick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel4)
                    .addComponent(txtNewPasswordConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnChangeNick)
                    .addComponent(btnChangePassword))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnChangeNickMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnChangeNickMouseClicked
        String uid = mMyUid;
        String nick = txtNewNick.getText();
        mParent.mServerClient.changeNick(uid, nick);
        mParent.setNick(nick);
        JOptionPane.showMessageDialog(ChatApp.getApplication().getMainFrame(), "更改昵称成功！");
        dispose();
    }//GEN-LAST:event_btnChangeNickMouseClicked

    private void btnChangePasswordMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnChangePasswordMouseClicked
        String uid = mMyUid;
        String newPassword = txtNewPassword.getText();
        String newPasswordConfirm = txtNewPasswordConfirm.getText();
        mParent.mServerClient.changePassword(uid, newPassword);
        JOptionPane.showMessageDialog(ChatApp.getApplication().getMainFrame(), "更改密码成功！");
        dispose();
    }//GEN-LAST:event_btnChangePasswordMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangeNick;
    private javax.swing.JButton btnChangePassword;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel lblOldNick;
    private javax.swing.JTextField txtNewNick;
    private javax.swing.JTextField txtNewPassword;
    private javax.swing.JTextField txtNewPasswordConfirm;
    // End of variables declaration//GEN-END:variables
}
